home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / ooo / f_0020 / sbasic.jar / text / sbasic / common / 03132000.xml < prev    next >
Encoding:
Extensible Markup Language  |  2003-08-01  |  10.9 KB  |  110 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>CreateUnoListener Function [Runtime]</title><meta name="filename" content="text/sbasic/common/03132000"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         table.Tabelle2{
  5.                 }
  6.         span.Tabelle2A{
  7.                 width:1.499cm;}
  8.         span.Tabelle2B{
  9.                 width:16.499cm;}
  10.         p.P1{
  11.                 }
  12.         p.P2{
  13.                 }
  14.         p.P3{
  15.                 }
  16.         span.T1{
  17.                 font-weight:bold;}
  18.         span.fr1{
  19.                 }
  20.         </style></head><body>
  21.   
  22.   
  23.   <help:paragraphinfo state="E" xmlns:help="http://openoffice.org/2000/help"/><help:to-be-embedded Eid="createunolistener" xmlns:help="http://openoffice.org/2000/help">
  24.   <p class="Head1"><help:paragraphinfo state="U" number="53"/><help:key-word value="CreateUnoListener; function" tag="kw68607_1"/><help:link Id="68607">CreateUnoListener Function [Runtime]</help:link></p>
  25.   <p class="Paragraph"><help:paragraphinfo state="U" number="52"/>Creates a Listener instance.</p>
  26.   <help:paragraphinfo state="E"/></help:to-be-embedded>
  27.   <p class="Paragraph"><help:paragraphinfo state="U" number="51" xmlns:help="http://openoffice.org/2000/help"/>Many Uno interfaces let you register listeners on a special listener interface. This allows you to listen for specific events and call up the appropriate listener method. The CreateUnoListener function waits for the called listener interface and then passes the interface an object that the interface supports. This object is then passed to the method to register the listener.</p>
  28.   <p class="Head2"><help:paragraphinfo state="U" number="50" xmlns:help="http://openoffice.org/2000/help"/>Syntax:</p>
  29.   <p class="Paragraph"><help:paragraphinfo state="U" number="49" xmlns:help="http://openoffice.org/2000/help"/>oListener = CreateUnoListener( Prefixname, ListenerInterfaceName )</p>
  30.   <p class="Head2"><help:paragraphinfo state="U" number="48" xmlns:help="http://openoffice.org/2000/help"/>Example:</p>
  31.   <p class="Paragraph"><help:paragraphinfo state="U" number="47" xmlns:help="http://openoffice.org/2000/help"/>The following example is based on a Basic library object.</p>
  32.   <p class="PropText"><help:paragraphinfo state="U" number="46" xmlns:help="http://openoffice.org/2000/help"/>Dim oListener</p>
  33.   <p class="PropText"><help:paragraphinfo state="U" number="45" xmlns:help="http://openoffice.org/2000/help"/>oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" )</p>
  34.   <p class="Paragraph"><help:paragraphinfo state="U" number="44" xmlns:help="http://openoffice.org/2000/help"/>The CreateUnoListener method requires two parameters. The first is a prefix and is explained in detail below. The second parameter is the fully qualified name of the Listener interface that you want to use.</p>
  35.   <p class="Paragraph"><help:paragraphinfo state="U" number="43" xmlns:help="http://openoffice.org/2000/help"/>The Listener must then be added to the Broadcaster Object. This is done by calling the appropriate method for adding a Listener. These methods always follow the pattern "addFooListener", where "Foo" is the Listener Interface Type, without the 'X'. In this example, the addContainerListener method is called to register the XContainerListener:</p>
  36.   <p class="PropText"><help:paragraphinfo state="U" number="42" xmlns:help="http://openoffice.org/2000/help"/>Dim oLib</p>
  37.   <p class="PropText"><help:paragraphinfo state="U" number="41" xmlns:help="http://openoffice.org/2000/help"/>oLib = BasicLibraries.Library1 ' Library1 must exist!</p>
  38.   <p class="PropText"><help:paragraphinfo state="U" number="40" xmlns:help="http://openoffice.org/2000/help"/>oLib.addContainerListener( oListener ) ' Register the listener</p>
  39.   <p class="Paragraph"><help:paragraphinfo state="U" number="39" xmlns:help="http://openoffice.org/2000/help"/>The Listener is now registered. When an event occurs, the corresponding Listener calls the appropriate method from the com.sun.star.container.XContainerListener Interface.</p>
  40.   <p class="Paragraph"><help:paragraphinfo state="U" number="38" xmlns:help="http://openoffice.org/2000/help"/>The prefix calls registered Listeners from Basic-subroutines. The Basic run-time system searches for Basic-subroutines or functions that have the name "PrefixListenerMethode" and calls them when found. Otherwise, a run-time error occurs.</p>
  41.   <p class="Paragraph"><help:paragraphinfo state="U" number="37" xmlns:help="http://openoffice.org/2000/help"/>In this example, the Listener-Interface uses the following methods:</p>
  42.   <ul class="L1">
  43.    <li class="">
  44.     <p class="P2"><help:paragraphinfo state="U" number="36" xmlns:help="http://openoffice.org/2000/help"/>disposing:</p>
  45.    </li>
  46.    <li class="">
  47.     <p class="P2"><help:paragraphinfo state="U" number="35" xmlns:help="http://openoffice.org/2000/help"/>Listener base interface (com.sun.star.lang.XEventListener): base interface for all Listener Interfaces</p>
  48.    </li>
  49.    <li class="">
  50.     <p class="P2"><help:paragraphinfo state="U" number="34" xmlns:help="http://openoffice.org/2000/help"/>elementInserted:</p>
  51.    </li>
  52.    <li class="">
  53.     <p class="P2"><help:paragraphinfo state="U" number="33" xmlns:help="http://openoffice.org/2000/help"/>Methode des Interface com.sun.star.container.XContainerListener</p>
  54.    </li>
  55.    <li class="">
  56.     <p class="P2"><help:paragraphinfo state="U" number="32" xmlns:help="http://openoffice.org/2000/help"/>elementRemoved:</p>
  57.    </li>
  58.    <li class="">
  59.     <p class="P2"><help:paragraphinfo state="U" number="31" xmlns:help="http://openoffice.org/2000/help"/>Method of the com.sun.star.container.XContainerListener interface</p>
  60.    </li>
  61.    <li class="">
  62.     <p class="P2"><help:paragraphinfo state="U" number="30" xmlns:help="http://openoffice.org/2000/help"/>elementReplaced:</p>
  63.    </li>
  64.    <li class="">
  65.     <p class="P2"><help:paragraphinfo state="U" number="29" xmlns:help="http://openoffice.org/2000/help"/>Method of the com.sun.star.container.XContainerListener interface</p>
  66.    </li>
  67.   </ul>
  68.   <p class="Paragraph"><help:paragraphinfo state="U" number="28" xmlns:help="http://openoffice.org/2000/help"/>In this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic:</p>
  69.   <ul class="L2">
  70.    <li class="">
  71.     <p class="P3"><help:paragraphinfo state="U" number="27" xmlns:help="http://openoffice.org/2000/help"/>ContListener_disposing</p>
  72.    </li>
  73.    <li class="">
  74.     <p class="P3"><help:paragraphinfo state="U" number="26" xmlns:help="http://openoffice.org/2000/help"/>ContListener_elementInserted</p>
  75.    </li>
  76.    <li class="">
  77.     <p class="P3"><help:paragraphinfo state="U" number="25" xmlns:help="http://openoffice.org/2000/help"/>ContListener_elementRemoved</p>
  78.    </li>
  79.    <li class="">
  80.     <p class="P3"><help:paragraphinfo state="U" number="24" xmlns:help="http://openoffice.org/2000/help"/>ContListener_elementReplaced</p>
  81.    </li>
  82.   </ul>
  83.   <p class="Paragraph"><help:paragraphinfo state="U" number="23" xmlns:help="http://openoffice.org/2000/help"/>An event structure type that contains information about an event exists for every Listener type. When a Listener method is called, an instance of this event is passed to the method as a parameter. Basic Listener methods can also call these event objects, so long as the appropriate parameter is passed in the Sub declaration. For example:</p>
  84.   <p class="PropText"><help:paragraphinfo state="U" number="22" xmlns:help="http://openoffice.org/2000/help"/>Sub ContListener_disposing( oEvent )</p>
  85.   <p class="PropText"><help:paragraphinfo state="U" number="21" xmlns:help="http://openoffice.org/2000/help"/>MsgBox "disposing"</p>
  86.   <p class="PropText"><help:paragraphinfo state="U" number="20" xmlns:help="http://openoffice.org/2000/help"/>MsgBox oEvent.Dbg_Properties</p>
  87.   <p class="PropText"><help:paragraphinfo state="U" number="19" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  88.   <p class="PropText"><help:paragraphinfo state="U" number="18" xmlns:help="http://openoffice.org/2000/help"/>Sub ContListener_elementInserted( oEvent )</p>
  89.   <p class="PropText"><help:paragraphinfo state="U" number="17" xmlns:help="http://openoffice.org/2000/help"/>MsgBox "elementInserted"</p>
  90.   <p class="PropText"><help:paragraphinfo state="U" number="16" xmlns:help="http://openoffice.org/2000/help"/>MsgBox oEvent.Dbg_Properties</p>
  91.   <p class="PropText"><help:paragraphinfo state="U" number="15" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  92.   <p class="PropText"><help:paragraphinfo state="U" number="14" xmlns:help="http://openoffice.org/2000/help"/>Sub ContListener_elementRemoved( oEvent )</p>
  93.   <p class="PropText"><help:paragraphinfo state="U" number="13" xmlns:help="http://openoffice.org/2000/help"/>MsgBox "elementRemoved"</p>
  94.   <p class="PropText"><help:paragraphinfo state="U" number="12" xmlns:help="http://openoffice.org/2000/help"/>MsgBox oEvent.Dbg_Properties</p>
  95.   <p class="PropText"><help:paragraphinfo state="U" number="11" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  96.   <p class="PropText"><help:paragraphinfo state="U" number="10" xmlns:help="http://openoffice.org/2000/help"/>Sub ContListener_elementReplaced( oEvent )</p>
  97.   <p class="PropText"><help:paragraphinfo state="U" number="9" xmlns:help="http://openoffice.org/2000/help"/>MsgBox "elementReplaced"</p>
  98.   <p class="PropText"><help:paragraphinfo state="U" number="8" xmlns:help="http://openoffice.org/2000/help"/>MsgBox oEvent.Dbg_Properties</p>
  99.   <p class="PropText"><help:paragraphinfo state="U" number="7" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  100.   <p class="Paragraph"><help:paragraphinfo state="U" number="6" xmlns:help="http://openoffice.org/2000/help"/>You do not need to include the parameter of an event object if the object is not used:</p>
  101.   <p class="PropText"><help:paragraphinfo state="U" number="5" xmlns:help="http://openoffice.org/2000/help"/>' Minimal implementation of Sub disposing</p>
  102.   <p class="PropText"><help:paragraphinfo state="U" number="4" xmlns:help="http://openoffice.org/2000/help"/>Sub ContListener_disposing</p>
  103.   <p class="PropText"><help:paragraphinfo state="U" number="3" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  104.   <table><tr class=""><th style="text-align:left;"><span class="Tabelle2A">
  105.       <p class="Paragraph"><draw:image draw:name="Icon0" svg:desc="This icon marks text containing important information on data and system security." svg:pixelx="32" svg:pixely="32" svg:width="0.847cm" svg:height="0.847cm" xlink:href="65640" draw:filter-name="" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/></p>
  106.  
  107.      </span></th><th style="text-align:left;"><span class="Tabelle2B">
  108.       <p class="Paragraph"><help:paragraphinfo state="U" number="2" xmlns:help="http://openoffice.org/2000/help"/>Listener methods must <span class="T1">always</span> be implemented to avoid Basic run-time errors.</p>
  109.      </span></th></tr></table>
  110.  </body></html>